﻿using Castle.DynamicProxy;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Castle.AOP.Demo
{
    internal class LoggingInterceptor : IInterceptor
    {
        public void Intercept(DynamicProxy.IInvocation invocation)
        {
            var methodName = invocation.Method.Name;
            try
            {
                Console.WriteLine(string.Format("执行方法:{0}, 参数: {1}", methodName, string.Join(",", invocation.Arguments)));
                invocation.Proceed();
                Console.WriteLine(string.Format("成功执行了方法:{0}", methodName));
            }
            catch (Exception e)
            {
                Console.WriteLine(string.Format("方法:{0}, 异常信息:{1}", methodName, e.Message));
                throw;
            }
            finally
            {
                Console.WriteLine(string.Format("退出方法:{0}", methodName));
            }
        }
    }
}
